<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改文章')" />
    <th:block th:include="include :: ckeditor-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-article-edit" th:object="${bArticle}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <textarea id="editor1" name="content" th:field="*{content}"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">语言：</label>
                <div class="col-sm-8">
                    <select name="language" class="form-control m-b" th:with="type=${@dict.getType('language')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{language}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">来源：</label>
                <div class="col-sm-8">
                    <input name="source" th:field="*{source}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">外链：</label>
                <div class="col-sm-8">
                    <input name="link" th:field="*{link}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">分类：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="articleclassid" type="hidden" th:field="*{articleclassid}" />
                        <input class="form-control" type="text" onclick="selectArticleclassTree()" id="treeName" readonly="true" th:field="*{parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ckeditor-js"/>
    <script th:inline="javascript">
        var editor;
        var prefix = ctx + "business/article";

        $("#form-article-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                editor.updateSourceElement();
                $.operate.save(prefix + "/edit", $('#form-article-edit').serialize());
            }
        }

        /*文章分类-新增-选择父部门树*/
        function selectArticleclassTree() {
            var options = {
                title: '文章分类选择',
                width: "380",
                url: ctx + "business/articleclass/selectArticleclassTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

        ClassicEditor
            .create( document.querySelector( '#editor1' ), {
                language:"zh-cn",
                ckfinder: {
                    uploadUrl: ctx + "businessfile/file/addfile",
                }
            } )
            .then( newEditor => {
                editor = newEditor;
            } )
            .catch( error => {
                console.error( error );
            } );
    </script>
</body>
</html>
